package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferSpecialCarCountDao;
import com.tianqu.tms.dto.TransferSpecialCarCountDto;

public class TransferSpecialCarCount extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5994959025435019814L;

	private int id;
	private String carType;
	private int quantity;
	private int quantity1;
	private int quantity2;
	private int quantity3;
	private int quantity4;
	private int quantity5;
	private String startWeekDate;
	private String endWeekDate;

	
	public TransferSpecialCarCount getTransferSpecialCarCountByWeekId(String endDate) throws TmsDaoException
	{
		TransferSpecialCarCountDao uDao = (TransferSpecialCarCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SPECIALCAR_COUNT);
		List<TransferSpecialCarCountDto> dtoList = uDao.getTransferSpecialCarCountByWeekId(endDate);
		TransferSpecialCarCount entity = null;
		if(dtoList!=null)
		{
			int quantity1=0;
			int quantity2=0;
			int quantity3=0;
			int quantity4=0;
			int quantity5=0;
			entity = new TransferSpecialCarCount();
			for(int i=0;i<dtoList.size();i++)
			{
				TransferSpecialCarCountDto dto = (TransferSpecialCarCountDto)dtoList.get(i);
				
				if(dto.getCarType()==1)
				{
					quantity1 = quantity1 + dto.getQuantity();
				}
				if(dto.getCarType()==2)
				{
					quantity2 = quantity2 + dto.getQuantity();
				}
				if(dto.getCarType()==3)
				{
					quantity3 = quantity3 + dto.getQuantity();
				}
				if(dto.getCarType()==4)
				{
					quantity4 = quantity4 + dto.getQuantity();
				}
				if(dto.getCarType()==5)
				{
					quantity5 = quantity5 + dto.getQuantity();
				}
			}
			entity.setQuantity1(quantity1);
			entity.setQuantity2(quantity2);
			entity.setQuantity3(quantity3);
			entity.setQuantity4(quantity4);
			entity.setQuantity5(quantity5);
		}
		return entity;
	}

	private String trnasCarType(int i)
	{
			switch (i) {
			case 1:
				return "微型面包车";
			case 2:
				return "大中型货车";
			case 3:
				return "大中型客车";
			case 4:
				return "危化品";
			case 5:
				return "校车";
			default:
				return "";
			}
	}
	/**
	 * 获取最新一条数据
	 * @return
	 * @throws TmsDaoException 
	 */
	public TransferSpecialCarCount getTransferCountWeekInfo(String endDateTime) throws TmsDaoException
	{
		TransferSpecialCarCountDao uDao = (TransferSpecialCarCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SPECIALCAR_COUNT);
		TransferSpecialCarCountDto dto = uDao.getTransferCountWeekInfo(endDateTime);
		TransferSpecialCarCount entity = null;
		if(dto!=null)
		{
			entity = new TransferSpecialCarCount();
			entity.setStartWeekDate(dto.getStartWeekDate());
			entity.setEndWeekDate(dto.getEndWeekDate());
		}
		return entity;
	}
	public List getTransferCountWeekList()throws TmsDaoException
	{
		TransferSpecialCarCountDao uDao = (TransferSpecialCarCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SPECIALCAR_COUNT);
		List<TransferSpecialCarCountDto> dtoList = uDao.getTransferCountWeekList();
		List list = null;
		if(dtoList!=null)
		{
			list = new ArrayList();
			if(dtoList.size() > 1)
			{
				int size = dtoList.size();
				if(dtoList.size()>20)
				{
					size=21;
				}
				for(int i=1;i<size;i++)
				{
					TransferSpecialCarCountDto dto = (TransferSpecialCarCountDto)dtoList.get(i);
					Map map = new HashMap();
					map.put("periodValue",dto.getStartWeekDate()+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+dto.getEndWeekDate());
					map.put("endWeekDate", dto.getEndWeekDate());
					list.add(map);
				}
			}
		}
		return list;
	}
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCarType() {
		return carType;
	}

	public void setCarType(String carType) {
		this.carType = carType;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public int getQuantity1() {
		return quantity1;
	}

	public void setQuantity1(int quantity1) {
		this.quantity1 = quantity1;
	}

	public int getQuantity2() {
		return quantity2;
	}

	public void setQuantity2(int quantity2) {
		this.quantity2 = quantity2;
	}

	public int getQuantity3() {
		return quantity3;
	}

	public void setQuantity3(int quantity3) {
		this.quantity3 = quantity3;
	}

	public int getQuantity4() {
		return quantity4;
	}

	public void setQuantity4(int quantity4) {
		this.quantity4 = quantity4;
	}

	public int getQuantity5() {
		return quantity5;
	}

	public void setQuantity5(int quantity5) {
		this.quantity5 = quantity5;
	}

	public String getStartWeekDate() {
		return startWeekDate;
	}

	public void setStartWeekDate(String startWeekDate) {
		this.startWeekDate = startWeekDate;
	}

	public String getEndWeekDate() {
		return endWeekDate;
	}

	public void setEndWeekDate(String endWeekDate) {
		this.endWeekDate = endWeekDate;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
